﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using BookStores.IDomain;
using Dapper.Database;

namespace BookStores.Domain
{
    /// <summary>
    /// 国家信息
    /// </summary>
    public class Country : ICountry
    {
        Contracts.ICountryRepository m_ICountryRepository = null;

        public Country(Contracts.ICountryRepository countryRepository)
        {
            m_ICountryRepository = countryRepository;
        }
        /// <summary>
        /// 根据关键字搜索国家列表
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<IEnumerable<Entity.Country>> GetCountries(string name, int pageIndex = 1, int pageSize = 10)
        {
            return await m_ICountryRepository.Queryable().Where(t => t.ID.Contains(name ?? "", StringComparison.OrdinalIgnoreCase)
                                                             || t.Name_CN.Contains(name ?? "", StringComparison.OrdinalIgnoreCase)
                                                             || t.Name_EN.Contains(name ?? "", StringComparison.OrdinalIgnoreCase))
                                                  .OrderBy(t => t.ID)
                                                  .ToPageListAsync(pageIndex, pageSize);
                    //.GetPageList<Entity.Country>(pageIndex
                    //                           , pageSize
                    //                           , "WHERE ID LIKE @keyWord OR Name_EN LIKE @KeyWord OR Name_CN LIKE @KeyWord ORDER BY ID "
                    //                           , new { keyWord = $"%{name}%" });
        }
    }
}
